package org.freedom.imarket.dao;

import java.util.List;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.SetUtils;
import org.freedom.imarket.entities.ListaSpesa;
import org.freedom.imarket.entities.User;
import org.freedom.imarket.repository.ListaSpesaRepository;
import org.freedom.imarket.repository.UserRepository;
import org.freedom.util.CheetahUtils;
import org.freedom.util.CloneHibernate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ResponseBody;

public class UserDAO extends AbstractEntityDAO<User>{

	@Autowired
	UserRepository repository;
	
	@Autowired
	ListaSpesaRepository listaSpesaRepository;
	
	@Transactional
	public  User findUserByUsernameAndPassword(String username,String password){
		User user =  ((UserRepository)getRepository()).findUserByUsername(username, password);
//		List<ListaSpesa> spesas = listaSpesaRepository.findByUser(user.getIdUser());
//		user.setListaSpesas(CheetahUtils.listToSet(spesas));
		
		return user;
	}
	
	@Override
	public JpaRepository<User, String> getRepository() {
		// TODO Auto-generated method stub
		return repository;
	}

	
	
	
}
